package com.codesynapse.controller;

import com.codesynapse.service.CodeSearchService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/code")
@RequiredArgsConstructor
public class CodeSearchController {

    private final CodeSearchService codeSearchService;

    @GetMapping("/search")
    public List<Map<String, Object>> searchCode(@RequestParam String query) throws IOException {
        return codeSearchService.searchCode(query);
    }

    @PostMapping("/index")
    public void indexCode(
            @RequestParam("file") MultipartFile file,
            @RequestParam("language") String language
    ) throws IOException {
        codeSearchService.indexCode(
                file.getOriginalFilename(),
                new String(file.getBytes()),
                language
        );
    }
} 